#ifndef mgr_game_mission_h
#define mgr_game_mission_h

#import "head.h"

class CMgrGameMission
{
public:
	/*mission state
	*/
	int mission_state;

	/*mission data
	*/
	int mission_id;
	int mission_type;
	int next_mission_id;

	int background_type;
	int start_bridge_point;
	char music_start[STRING_BUF_SIZE];
	char music_battle[STRING_BUF_SIZE];
	std::map<int, std::vector<SMissionEnemy> > enemy_table;

	int mission_piece_drop_max_count;
	int mission_piece_drop_probability[PIECE_TYPE_COUNT];

	/*mission enemy type list
	*/
	std::list<int> enemy_type_list;

	/*flag
	*/
	int group_index;
	int group_enemy_count;
	bool flag_group_delay_tick;
	int group_delay_tick_count;

	bool flag_enemy_disappear;
	int create_heart_tick;

	/*record backup
	*/
	RecordMission mission_recrod;

private:
	static CMgrGameMission *instance;

public:
	static void InitInstance(void);
	static void FreeInstance(void);
	static CMgrGameMission *Instance(void);

	void Update(void);

	/*mission state
	*/
	void SetMissionState(int State);

	void ToturialCreateHeart(void);
	void ToturialCreateEnemy(void);
	void ToturialEnemyMoveOver(void);
	void ToturialOver(void);

	/*event function
	*/
	void EventMissionStart(void);
	void EventEnemyKilled(sprite_game_enemy *Enemy);
	void EventEnemyDisappear(sprite_game_enemy *Enemy);
	void EventEnemyAttackSuccess(sprite_game_bomb *Bomb);
	void EventHeartGet(sprite_game_heart *Heart);
	void EventBridgeSuccess(void);
	void EventBridgeSuccessAniOver(void);
	void EventBridgeFailed(void);
	void EventEnemyAllKilledSuccess(void);

	/*load mission
	*/
	void LoadMission(int MissionID);

	/*mission control
	*/
	void MissionRestart(void);
	void MissionOver(void);
	void MissionTimeUp(void);
	void MissionNext(void);
	void MissionQuit(void);

	/*load and release resource
	*/
	void LoadResource(void);
	void FreeResource(void);

	/*load enemy table and data
	*/
	void LoadEnemyTable(mxml_node_t *Element);
	void LoadEnemyMovePath(mxml_node_t *Element, SMissionEnemyPathElement *Object);

	/*load element table to create enemy
	*/
	bool LoadGroup(void);       /*true : there have enemy, false : there is no more enemy*/
	void LoadEnemy(SMissionEnemy *Data);

protected:
	CMgrGameMission(void);
	~CMgrGameMission(void);

	void MissionWinRecordControl(void);
};

#endif